package com.whx.managea.service.impl;

import com.whx.managea.dao.GradeDao;
import com.whx.managea.entity.Grade;
import com.whx.managea.entity.Student;
import com.whx.managea.entity.vo.GradeVo;
import com.whx.managea.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;


@Service
public class GradeServiceImpl implements GradeService {

    @Autowired
    GradeDao gradeDao;


    @Override
    public GradeVo getGrade(String stui, String courseName) {
        int stuId=Integer.valueOf(stui);
        GradeVo gradeVo=gradeDao.selectGrade(stuId,courseName);
        return gradeVo;
    }


    //根据id删除成绩
    @Override
    public void deleteGradeById(Integer id) {
        try {
            if (id!=null){
                System.out.println(id);
                gradeDao.deleteGradeById(id);
            }

        }catch (Exception e){
            System.out.println(e);
        }

    }

    @Override
    public int save(Grade grade) {
     return    gradeDao.save(grade);
    }

    @Override
    public List<GradeVo> listGrades(Integer page,Integer rows,String searchCol,String searchValue) {
        List<GradeVo> list=new ArrayList<>();
        Integer start=(page-1)*rows;
        list=gradeDao.findAll(start,rows,searchCol,searchValue);
        return list;
    }


    @Override
    public Integer counts(String searchCol, String searchValue) {
        return gradeDao.counts(searchCol, searchValue);
    }

    @Override
    public Integer changeGrade(Grade grade) {

        return gradeDao.updateGrade(grade);
    }

}
